
from flask import Flask, render_template, make_response, Response

from flask import Flask, render_template, make_response, Response, redirect, abort

from flask import request

app = Flask(__name__)

#  单元测试 test_publish(self):会访问下面这个函数，获得响应
@app.route('/publist',methods=['POST'])
def publish_bank():
    data = '{"id":101,"age":20}'
    code = 200
    # 1.
    #return "预发布银行公告",200
    # 2.响应的方式
    # response = make_response(data,code)
    # # 根据数据的类型，设置响应头
    # response.headers['Content-Type'] = 'application/json;charset=utf-8'
    # return response

    # 3.
    response = Response(data,code,content_type="application/json")
    return response

    # 3.Response类
    response = Response(data,code,content_type="application/json")
    return response


@app.route('/add',methods=['GET','POST'])
def addCard():
    if request.method == "POST":
        # 接收开户信息
        bankId = request.form.get('bank')
        username = request.form.get('username')
        phone = request.form.get('phone')

        # 开户是判断之前该手机号是否已被注册
        if phone == '17791692095':
            # 中断，定义报错显示
            # 1.
            # abort(403)
            # 2.
            abort(Response("<h3 style='color:red'>当前手机号不能被注册</h3>"))

        # 验证数据是否为空
        # 假如操作成功
        # 进入列表页面
        # 重定向 相对路径
        return redirect('list')
    # GET请求，响应是开户页面
    return render_template('card/addcard.html')



@app.route('/list')
def listCard():
    return render_template('card/list.html')

@app.route('/find', methods=['GET', 'POST'])
def find():
    print('headers', request.headers)
    print('cookie',request.cookies)
    return render_template("requestsList.html", request=request)

app.run(host='0.0.0.0',
        port=5000,
        debug=True,
        threaded=True,
        processes=1
        )
